<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<!DOCTYPE html>
<html lang="en">
<head>
<title><s:message code="app.title" /></title>
<%@ include file="Include.jsp"%>
<script type="text/javascript">
	
	$(document).ready(function() {
		var oTable = $('#shippingBillTable').dataTable( {
			 	"bDestroy": true,
		        "bProcessing": false,
		        "iDisplayLength": 10,
		        "bFilter": false,
		        "bLengthChange": false,
		        "aoColumnDefs": [
		          { 'bSortable': false, 'aTargets': [2] }
		       	]
		 	} );
				
	});
	
	function edit(sbId){
		$('#shippingBillEditForm').attr('action','EditShippingBill?sbId='+sbId);
		
		$('#sbId').val(sbId);
		
		$('#shippingBillEditForm').attr('method','get');
		$('#shippingBillEditForm').submit();
	}
	
</script>
</head>
<body>
	<div class="container">
		<%@ include file="Menu.jsp"%>
		<h2><s:message code="shippingBillForm.addheader" /> (${jobregisterForm.jobno})</h2>
		<hr>
		<form:form id="cancelForm">
		</form:form>
		<form:form id="shippingBillEditForm" >
			<input type="hidden" id="sbId" name="sbId" />
		</form:form>
		
		<form:form class="form-horizontal" method="post" name="shippingbillForm" id="shippingbillForm" commandName="shippingbillForm"
	           modelAttribute="shippingbillForm" >
	    	<form:errors cssClass="text-error" path="*" />       
	           
	        <form:hidden path="sbid" />
	        <form:hidden path="creationdate" />
			
			<table class="table table-bordered">
				<tr>
					<form:hidden path="jobnoid" />
					<th><form:label path="cha"><s:message code="jobRegisterForm.chaid" /></form:label></th>
					<td>
						<s:message text="${jobregisterForm.cha}" />
					</td>
					<th><form:label path="directhubid"><s:message code="shippingBillForm.directhubid" /></form:label></th>
					<td>
						<form:select path="directhubid" cssClass="input-medium" tabindex="1">
							<form:option value="">- Select -</form:option> 
							<form:options items="${directhubList}" itemLabel="formvalue" itemValue="codetableid" />
						</form:select>
					</td>
				</tr>
				<tr>
					<th><form:label path="invoiceno"><s:message code="shippingBillForm.invoiceno" /></form:label></th>
					<td>
						<form:input path="invoiceno" cssClass="input-medium" id="invoiceno" maxlength="30" size="50" tabindex="2"/>
					</td>
					<th><form:label path="invoicedate"><s:message code="shippingBillForm.invoicedate" /></form:label></th>
					<td>
						<form:input path="invoicedate" cssClass="input-medium" id="invoicedate" maxlength="10" size="20" tabindex="2" placeholder="DD/MM/YYYY"/>
					</td>
					<th><form:label path="invoicepayterms"><s:message code="shippingBillForm.invoicepayterms" /></form:label></th>
					<td>
						<form:input path="invoicepayterms" cssClass="input-large" id="invoicepayterms" maxlength="40" size="50" tabindex="2" placeholder="ie. 100% Adv.Payment"/>
					</td>		
				</tr>
				<tr>
					<th><form:label path="sbillno"><s:message code="shippingBillForm.sbillno" /></form:label></th>
					<td>
						<form:input path="sbillno" cssClass="input-medium" id="sbillno" maxlength="7" size="20" tabindex="2"/>
					</td>
					<th><form:label path="sbilldate"><s:message code="shippingBillForm.sbilldate" /></form:label></th>
					<td>
						<form:input path="sbilldate" cssClass="input-medium" id="sbilldate" maxlength="10" size="20" tabindex="2" placeholder="DD/MM/YYYY"/>
					</td>
					<th><form:label path="fobvalueinr"><s:message code="shippingBillForm.fobvalueinr" /></form:label></th>
					<td>
						<form:input path="fobvalueinr" cssClass="input-medium" id="fobvalueinr" maxlength="11" size="11" tabindex="2"/>
					</td>
				</tr>
				<tr>
					<th><form:label path="incotermsid"><s:message code="shippingBillForm.incotermsid" /></form:label></th>
					<td>
						<form:select path="incotermsid" cssClass="input-medium" tabindex="1">
							<form:option value="">- Select -</form:option> 
							<form:options items="${incotermsList}" itemLabel="formvalue" itemValue="codetableid" />
						</form:select>
					</td>					
					<th><form:label path="currencyid"><s:message code="shippingBillForm.currencyid" /></form:label></th>
					<td>
						<form:select path="currencyid" cssClass="input-medium" tabindex="1">
							<form:option value="">- Select -</form:option> 
							<form:options items="${currencyList}" itemLabel="formvalue" itemValue="codetableid" />
						</form:select>
					</td>
					<th><form:label path="invoicevalue"><s:message code="shippingBillForm.invoicevalue" /></form:label></th>
					<td>
						<form:input path="invoicevalue" cssClass="input-medium" id="invoicevalue" maxlength="11" size="11" tabindex="2"/>
					</td>
				</tr>
			</table>
			<c:if test="${not empty shippingbillForm.sbid}">
				<button class="btn btn-primary" type="submit" formaction="EditShippingBill" formmethod="post" tabindex="7"><s:message code="app.add" /></button>
			</c:if>
			<c:if test="${empty shippingbillForm.sbid}">
				<button class="btn btn-primary" type="submit" formaction="ListShippingBill" formmethod="post" tabindex="7"><s:message code="app.add" /></button>
			</c:if>
			&nbsp;
			<button class="btn" type="submit" formaction="ListJobRegister?jobid=${param.jobnoid}" form="cancelForm" formmethod="get" tabindex="8"><s:message code="app.cancel" /></button>
		</form:form>
		<!--  Shipping Bill List Code Start -->
		<table class="table table-hover table-bordered" id="shippingBillTable">
				<thead>
					<tr>
						<th><s:message code="shippingBillForm.sbillno" /></th>
						<th><s:message code="shippingBillForm.sbilldate" /></th>
						<th><s:message code="shippingBillForm.invoicedate" /></th>
						<th><s:message code="shippingBillForm.currencyid" /></th>
						<th><s:message code="app.action" /></th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${shippingBillList}" var="sb" >
						<tr>
							<td>
								<c:out value="${sb.sbillno}" />
							</td>
							<td>
								<c:out value="${sb.sbilldate}" />
							</td>
							<td>
								<c:out value="${sb.invoicedate}" />
							</td>
							<td>
								<c:out value="${sb.currency}" />
							</td>
							<td>
								<a href="#" onclick="javascript: edit('${sb.sbid}');" >Edit</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
	</div>
</body>
</html>